<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="perm" uri="/tld/permission"%>
<%@page import="com.testingedu.common.QueryResult"%>
<%@page import="com.testingedu.model.TUser"%>
<%@page import="com.testingedu.model.TRole"%>
<%@ include file="../common/tiglib.jsp" %>
<%QueryResult queryResult  = (QueryResult)request.getAttribute("queryResult");
  TUser tUser = (TUser) request.getAttribute("tUser");%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>My JSP 'userList.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<STYLE type="text/css">
.STYLE11 {
	font-size: 15px;
	color: #03515d;
}

.STYLE4 {
	color: #03515d;
	font-size: 12px;
}

A IMG {
	border: 0
}
</STYLE>
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/css/pingTai/pingTai.css">
		<SCRIPT type="text/javascript" language="javascript"  src="${pageContext.request.contextPath}/js/jquery-1.7.2.js"></SCRIPT>
		<SCRIPT type="text/javascript">
		$(document).ready(function(){
			$('#addAll').click(function(){
				if($(this).attr('checked') == 'checked') {
					$("input:enabled[name='checkbox']").attr('checked','true');//全选
				} else {
					$("input:enabled[name='checkbox']").removeAttr('checked');//取消全选
				}
			});
			$('#submit').click(function(){
				$(this).attr('disabled','disabled');
				var parameter = "userId=<%=tUser.getId()%>&value=";
				var i = 0;
				$("input:checked:enabled[name='checkbox']").each(function(){
					parameter+=$(this).val()+'o';
					i++;
				});
				if(i == 0) {
					alert('未选中权限，请选中操作框中的单选按钮');
					return;
				}
				parameter = parameter.substring(0, parameter.length - 1);
				$.ajax({
	   				type: "POST",
	   				url: "${pageContext.request.contextPath}/admin/roleInUser/delete",
	   				data: parameter,
	   				success: function(){
	   					$("input:checked:enabled[name='checkbox']").each(function(){
							$(this).remove();
							$('#id_'+$(this).val()+'').html('已移除');
						});
	     				alert( "移除权限成功");
	  				},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
   						alert("操作时发生了错误，请重试");
					}
				});
				$(this).removeAttr('disabled');
			});
		});
		function pageGo(goToPage) {
			if(<%=queryResult.getCurrentPage() %> == goToPage) {
				return;
			}
			if(<%=queryResult.getAllPage() %> < goToPage) {
				return;
			}
			window.location.href = "${pageContext.request.contextPath}/admin/roleInUser?target=delete&url=jsp&userId=<%=tUser.getId() %>&_currentPage="+goToPage;
		}
		</SCRIPT>
	</head>

	<body>
		<table width="100%" border="0" align="center" cellpadding="0"
			cellspacing="0">
			<tr height="20" valign="baseline">
				<td bgcolor="#353c44">
					<img src="${pageContext.request.contextPath}/images/pingTai/tb.gif"
						width="14" height="14" />
					<span class="STYLE1"><font color="white">角色查询</font> </span>
				</td>
				<td align="right" bgcolor="#353c44">
					<span class="STYLE1"> </span>
				</td>
			</tr>
			<tr>
				<td height="3" colspan="2"></td>
			</tr>
		</table>
		<form
			action="${pageContext.request.contextPath}/admin/roleInUser?target=delete&userId=<%=tUser.getId()%>&url=jsp"
			method="post">
			<table width="100%" border="0" cellpadding="0" cellspacing="1"
				bgcolor="#a8c7ce">
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="35%">
						角色名:
					</td>
					<td width="65%">
						<input type="text" name="name" size="50">
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td colspan="4" align="center">
						<input type="submit" value="查询" class="button2" />
						&nbsp;&nbsp;
						<input type="reset" value="重置" class="button2" />
					</td>
				</tr>
			</table>
		</form>
		<table width="100%" border="0" align="center" cellpadding="0"
			cellspacing="0">
			<tr>
				<td height="3"></td>
			</tr>
			<tr height="20" valign="baseline">
				<td bgcolor="#353c44">
					<img src="${pageContext.request.contextPath}/images/pingTai/tb.gif"
						width="14" height="14" />
					<span class="STYLE1" >移除角色权限&nbsp;&nbsp;&nbsp;&nbsp;-->&nbsp;&nbsp;&nbsp;&nbsp;角色名：<%=tUser.getName() %></span>
				</td>
				<td align="right" bgcolor="#353c44">
					<span class="STYLE1"> </span>
				</td>
			</tr>
			<tr>
				<td height="3" colspan="2"></td>
			</tr>
		</table>
		<table width="100%" border="0" cellpadding="0" cellspacing="1"
			bgcolor="#a8c7ce" onmouseover="changeto()" onmouseout="changeback()"
			onclick="clickto()">
			<tr id="orderTr" align="center" class="STYLE10" height="20"
				bgcolor="d3eaef">
				<td width="15%">
					序号
				</td>
				<td width="25%">
					权限名
				</td>
				<td width="30%">
					<input type="checkbox" id="addAll">全选
				</td>
			</tr>
			<%
					for(int i = 0 ; i < queryResult.getResultList().size(); i++) {
						TRole tRole = (TRole)queryResult.getResultList().get(i);
					%>
				<tr align="center" bgcolor="#FFFFFF" class="STYLE19">
					<td>
						<%=(i+1) %>
					</td>
					<td>
						<%=tRole.getName() %>
					</td>
					<td>
						<font color="red" id="id_<%=tRole.getId() %>"></font><input type="checkbox" name="checkbox" value="<%=tRole.getId() %>">
					</td>
				</tr>
			<%} %>
		</table>
		<table width="100%" border="0" cellspacing="0" cellpadding="0"
			align="right">
			<tr>
				<td class="STYLE4" valign="middle">
					&nbsp;&nbsp;共有
					<%=queryResult.getAllCount() %>
					条记录，当前第
					<%=queryResult.getCurrentPage() %>
					/
					<%=queryResult.getAllPage() %>
					页
				</td>
				<td align="center">
					<button class="button4" id="submit">确定移除</button>
				</td>
				<td colspan="4" align="center">
					<input type="button" value="返回"
						onclick="javascript:history.go(-1);" class="button2" />
				</td>
				<td>
					<table border="0" align="right" cellpadding="0" cellspacing="0">
						<tr>
							<td width="40" height="20" valign="middle">
								<a href="javascript:pageGo(1)"><img
										src="${pageContext.request.contextPath}/images/page/first.gif" />
								</a>
							</td>
							<%if(queryResult.getCurrentPage() > 1) {%>
								<td width="40" height="20" valign="middle">
									<a
										href="javascript:pageGo(<%=(queryResult.getCurrentPage() - 1) %>)"><img
											src="${pageContext.request.contextPath}/images/page/back.gif"
											width="43" height="15" /> </a>
								</td>
							<%} %>
							<%if(queryResult.getCurrentPage() < queryResult.getAllPage()) {%>
								<td width="45" height="20" valign="middle">
									<a
										href="javascript:pageGo(<%=(queryResult.getCurrentPage() + 1) %>)"><img
											src="${pageContext.request.contextPath}/images/page/next.gif"
											width="43" height="15" /> </a>
								</td>
							<%} %>
							<td width="40" height="20" valign="middle">
								<a
									href="javascript:pageGo(<%=(queryResult.getAllPage()) %>)"><img
										src="${pageContext.request.contextPath}/images/page/last.gif"
										width="37" height="15" /> </a>
							</td>
							<td width="140" height="20" valign="bottom">
								<span class="STYLE11">&nbsp;转到第<input type="text"
										size="4" name="currentPage" id="goToPage"
										style="height: 20px; width: 20px; border: 1px solid #999999;text-align: center;" />页
									<button
										onclick="pageGo(document.getElementById('goToPage').value)">
										GO
									</button> </span>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</body>
</html>
